package com.qiu.greened.utils

import android.annotation.SuppressLint
import android.app.Application
import android.content.Context
import android.content.Intent
import android.content.SharedPreferences
import androidx.core.content.ContextCompat
import androidx.core.content.ContextCompat.startActivity
import com.qiu.greened.ui.my.LoginActivity

class MyData : Application() {

    companion object {
        @SuppressLint("StaticFieldLeak")
        lateinit var context: Context
        var login: Boolean = false
        lateinit var token: String
        var userId: Int = -1

        fun setLoginData() {
            login = true
            val save = context.getSharedPreferences("data", Context.MODE_PRIVATE)
            token = save.getString("token", "").toString()
            userId = save.getInt("userId", -1)
        }
    }

    override fun onCreate() {
        super.onCreate()
        context = applicationContext
        if (context.getSharedPreferences("data", Context.MODE_PRIVATE)
                .getString("phone", "") != ""
        ) {
            setLoginData()

        }
    }

}